using System;
using System.IO;

namespace LocalBoard.Persistence
{
	/// <summary>
	/// Summary description for TestSqlAccessorWithMultiClub.
	/// </summary>
	[NUnit.Framework.TestFixture]
	public class TestSqlAccessorWithMultiClub : TestAccessorWithMultiClub
	{
		private string _dbTestServer = "ac03ama22572";
		private string _dbTestDatabase = "TestLocalBoard";
		private string _dbTestUserId = "sa";
		private string _dbTestPassword = "unreal9!";
		private string _dbCreateScriptFile = "rebuild.sql";
		private string _dbCreateOutFile = "rebuild.res";
		private string _dbCleanScriptFile = "cleantables.sql";
		private string _dbCleanOutFile = "cleantables.res";

		[NUnit.Framework.SetUp]
		public new void setUp()
		{
			System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("osql", "/S " + _dbTestServer + " /d " + _dbTestDatabase + " /U " + _dbTestUserId + " /P " + _dbTestPassword + " /i " + _dbCreateScriptFile + " /o " + _dbCreateOutFile);
			startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
			System.Diagnostics.Process process = System.Diagnostics.Process.Start(startInfo);
			process.WaitForExit();
			if(!File.Exists(_dbCreateOutFile))
			{
				NUnit.Framework.Assert.Fail("Re-Create objects script result does not exists.");
			}
			SqlAccessor.SqlDataAccessBase.SetDbServer(_dbTestServer);
			SqlAccessor.SqlDataAccessBase.SetDbDatabase(_dbTestDatabase);
			SqlAccessor.SqlDataAccessBase.SetDbUserIdAndPassword(_dbTestUserId, _dbTestPassword);

			IAccessorFactory accessorFactory = new SqlAccessorFactory();
			_attachmentAccessor = accessorFactory.GetAttachmentAccessor();
			_boardAccessor = accessorFactory.GetBoardAccessor();
			_clubAccessor = accessorFactory.GetClubAccessor();
			_commentAccessor = accessorFactory.GetCommentAccessor();
			_messageAccessor = accessorFactory.GetMessageAccessor();
			_pollItemAccessor = accessorFactory.GetPollItemAccessor();
			_profileAccessor = accessorFactory.GetProfileAccessor();
			_userRoleAccessor = accessorFactory.GetUserRoleAccessor();
			_clubRoleAccessor = accessorFactory.GetClubRoleAccessor();
			_clubProfileAccessor = accessorFactory.GetClubProfileAccessor();

			_clubOne = _clubAccessor.Get(1);
			_clubTwo = _clubAccessor.Get(2);
		}
		[NUnit.Framework.TearDown]
		public new void tearDown()
		{
			_attachmentAccessor = null;
			_boardAccessor = null;
			_clubAccessor = null;
			_commentAccessor = null;
			_messageAccessor = null;
			_pollItemAccessor = null;
			_profileAccessor = null;
			_userRoleAccessor = null;
			_clubRoleAccessor = null;
			_clubProfileAccessor = null;

			_clubOne = null;
			_clubTwo = null;
			System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("osql", "/S " + _dbTestServer + " /d " + _dbTestDatabase + " /U " + _dbTestUserId + " /P " + _dbTestPassword + " /i " + _dbCleanScriptFile + " /o " + _dbCreateOutFile);
			startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
			System.Diagnostics.Process process = System.Diagnostics.Process.Start(startInfo);
			process.WaitForExit();
			if(!File.Exists(_dbCleanOutFile))
			{
				NUnit.Framework.Assert.Fail("Clean tables script result does not exists.");
			}
		}
	}
}
